<template>
	<view class="newOrder">
		<view class="form">
			<view class="form_item1">
				<view class="text"> <text>*</text>公司名称: </view>
				<view class="input">
					<input v-model="name" type="text" placeholder="请输入公司名称" />
				</view>
			</view>
			<view class="form_item1">
				<view class="text"> <text></text>公司地址: </view>
				<view class="input">
					<input v-model="adress" type="text" placeholder="请输入公司地址" />
				</view>
			</view>

			<view class="form_item1">
				<view class="text"> <text></text>公司电话: </view>
				<view class="input">
					<input v-model="tel" class="note" type="digit" placeholder="请输入公司电话" />
				</view>
			</view>
		</view>
		<view class="btn" @tap="edit"> 修改 </view>
	</view>
</template>

<script>
	var app = getApp();
	export default {
		data() {
			return {
				name: "",
				adress: "",
				tel: "",
			};
		},
		onShow() {
			// console.log(app.globalData.userInfo)
			this.name = app.globalData.userInfo.mchCompany ? app.globalData.userInfo.mchCompany : ""
			this.adress = app.globalData.userInfo.mchAddress ? app.globalData.userInfo.mchAddress : ""
			this.tel = app.globalData.userInfo.mchTel ? app.globalData.userInfo.mchTel : ""
		},
		methods: {
			edit() {
				var that = this;
				if (this.name == "") {
					uni.showToast({
						title: "请输入公司名称",
						icon: "none"
					})
					return
				}
				// if (this.adress == "") {
				// 	uni.showToast({
				// 		title: "请输入公司地址",
				// 		icon: "none"
				// 	})
				// 	return
				// }
				// if (this.tel == "") {
				// 	uni.showToast({
				// 		title: "请输入公司电话",
				// 		icon: "none"
				// 	})
				// 	return
				// }
				this.$api.currUserDetailApi({
					mchCompany:this.name,
					mchAddress:this.adress,
					mchTel:this.tel
				}).then(res => {
					// console.log(res)
					if (res.code == 200) {
						uni.showToast({
							title: "恭喜，修改成功",
							icon: "none"
						})
						app.globalData.userInfo.mchCompany = that.name;
						app.globalData.userInfo.mchAddress = that.adress;
						app.globalData.userInfo.mchTel = that.tel;
						
						uni.navigateBack({
							delta:1
						})
						
					}
				})
			}
		}
	};
</script>

<style lang="scss" scoped>
	page {
		background-color: #fff;
		height: 100vh;
	}

	.newOrder {
		background-color: #fff;
		height: 100vh;

		.form {
			padding: 38rpx 68rpx 32rpx 68rpx;
			background-color: #fff;
			// margin-top: 38rpx;

			.form_item1 {
				color: #bdbdbd;
				margin-bottom: 36rpx;
				text-indent: 1em;
				display: flex;
				align-items: center;

				.text {
					font-size: 0.875rem;
					margin-bottom: 22rpx;

					text {
						color: #fe3430;
					}
				}

				.input {
					display: flex;
					align-items: center;
					flex: 1;
					margin-left: 20rpx;

					input {
						height: 94rpx;
						width: 100%;
						background: #f2f2f2;
						border-radius: 47rpx;
						text-indent: 1em;
						color: #000;
					}

					button {
						width: 73rpx;
						height: 38rpx;
						background: #fe3430;
						border-radius: 49rpx;
						color: #fff;
					}
				}
			}

			.btn {
				display: flex;

				button {
					height: 58rpx;
					line-height: 58rpx;
					background: #fe3430;
					border-radius: 49rpx;
					color: #fff;
					margin-left: 0;
					margin-right: 10rpx;
				}
			}
		}

		.btn {
			background-image: url("/static/images/Registration/button.png");
			background-size: 280rpx 123rpx;
			color: #fff;
			width: 280rpx;
			height: 123rpx;
			line-height: 100rpx;
			text-align: center;
			margin-left: 50%;
			transform: translateX(-50%);
			border-radius: 49rpx;
		}
	}
</style>